package com.yenlien.traceyun.business.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.business.service.rest.usercenter.DepartmentRestService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by LiuSha on 2020/6/12.
 */
@RestController
@RequestMapping("/department")
public class DepartmentController extends BaseController {
    @Autowired
    private DepartmentRestService departmentRestService;
//    @Autowired
//    private ResourceService resourceService;

    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody JSONObject jsonObject) {
        return departmentRestService.findByList(jsonObject);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody JSONObject jsonObject) {
        jsonObject.put("companyId", UserAuthUtil.getLoginUser().getCompanyId());
        return departmentRestService.save(jsonObject);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Object update(@RequestBody JSONObject jsonObject) {
        return departmentRestService.update(jsonObject);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Object delete(@PathVariable String id) {
        return departmentRestService.delete(id);
    }

    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable String id) {
        return departmentRestService.findById(id);
    }

    @RequestMapping(value = "/findByAll", method = RequestMethod.GET)
    public Object findByAll() {
        return departmentRestService.findByAll(UserAuthUtil.getLoginUser().getCompanyId());
    }

    @PostMapping(value = "/bindresource")
    public Object bindResources(@RequestBody JSONObject params) {
        return departmentRestService.bindResources(params);
    }

    @GetMapping(value = "/loadresource/{id}")
    public Object loadResources(@PathVariable("id") String id) {
        return departmentRestService.loadResources(id);
    }

//    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
//    public Object delete(@PathVariable String id) {
//        departmentService.delete(id);
//        return success("success");
//    }

//    //查看部门权限
//    @RequestMapping(value = "/findByMenu/{id}", method = RequestMethod.GET)
//    public Object findByMenu(@PathVariable String id) throws BusinessException {
//        return success(resourceService.findByMenu(id));
//    }

//    //添加部门权限
//    @RequestMapping(value = "/saveMenu", method = RequestMethod.POST)
//    public Object saveMenu(@RequestBody Department department) throws BusinessException {
//        resourceService.saveDeptMenu(department);
//        return success("success");
//    }
}
